<?php

namespace App\Listeners;

use App\Events\OrderCompletedEvent;
use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;

class SendNotifications implements ShouldQueue
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\OrderCompletedEvent  $event
     * @return void
     */
    public function handle(OrderCompletedEvent $event)
    {
        $orderInfo = $event->orderInfo;

        $access = 'IPX' . $orderInfo->user_id . '@ipxproxy.com';
        $email = User::where('id', $orderInfo->user_id)->value('email');
        $proxy_type = $orderInfo->proxy_type == 1 ? '动态代理' : '静态代理';
        $content = "*新订单提醒*\n订单号：{$orderInfo->order_nu}\n用户账号：{$email}\n内部账号：{$access}\n代理类型：{$proxy_type}\n套餐：{$orderInfo->goods_info}\n支付方式/金额：{$orderInfo->pay_way}/{$orderInfo->amount}";

        sendNotification($content);
    }
}
